<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- /fasttmp/mkdist-qt-4.3.5-1211793125/qtopia-core-opensource-src-4.3.5/doc/src/plugins-howto.qdoc -->
<head>
  <title>Qt 4.3: How to Create Qt Plugins</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
<td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">How to Create Qt Plugins<br /><small></small></h1>
<a name="qt-debug-plugins"></a><a name="qt-no-plugin-check"></a><p>Qt provides two APIs for creating plugins:</p>
<ul>
<li>A higher-level API for writing extensions to Qt itself: custom database drivers, image formats, text codecs, custom styles, etc.</li>
<li>A lower-lever API for extending Qt applications.</li>
</ul>
<p>For example, if you want to write a custom <a href="qstyle.html">QStyle</a> subclass and have Qt applications load it dynamically, you would use the higher-level API.</p>
<p>Since the higher-level API is built on top of the lower-level API, some issues are common to both.</p>
<p>If you want to provide plugins for use with <i>Qt Designer</i>, see the <a href="qtdesigner.html">QtDesigner</a> module documentation.</p>
<p>Topics:</p>
<ul><li><a href="#the-higher-level-api-writing-qt-extensions">The Higher-Level API: Writing Qt Extensions</a></li>
<li><a href="#the-lower-level-api-extending-qt-applications">The Lower-Level API: Extending Qt Applications</a></li>
<li><a href="#loading-and-verifying-plugins-dynamically">Loading and Verifying Plugins Dynamically</a></li>
<ul><li><a href="#the-build-key">The Build Key</a></li>
</ul>
<li><a href="#static-plugins">Static Plugins</a></li>
<li><a href="#the-plugin-cache">The Plugin Cache</a></li>
<li><a href="#debugging-plugins">Debugging Plugins</a></li>
</ul>
<a name="the-higher-level-api-writing-qt-extensions"></a>
<h2>The Higher-Level API: Writing Qt Extensions</h2>
<p>Writing a plugin that extends Qt itself is achieved by subclassing the appropriate plugin base class, implementing a few functions, and adding a macro.</p>
<p>There are several plugin base classes. Derived plugins are stored by default in sub-directories of the standard plugin directory. Qt will not find plugins if they are not stored in the right directory.</p>
<p><table align="center" cellpadding="2" cellspacing="1" border="0">
<thead><tr valign="top" class="qt-style"><th>Base Class</th><th>Directory Name</th><th>Key Case Sensitivity</th></tr></thead>
<tr valign="top" class="odd"><td><a href="qaccessiblebridgeplugin.html">QAccessibleBridgePlugin</a></td><td><tt>accessiblebridge</tt></td><td>Case Sensitive</td></tr>
<tr valign="top" class="even"><td><a href="qaccessibleplugin.html">QAccessiblePlugin</a></td><td><tt>accessible</tt></td><td>Case Sensitive</td></tr>
<tr valign="top" class="odd"><td><a href="qdecorationplugin.html">QDecorationPlugin</a></td><td><tt>decorations</tt></td><td>Case Sensitive</td></tr>
<tr valign="top" class="even"><td><a href="qiconengineplugin.html">QIconEnginePlugin</a></td><td><tt>iconengines</tt></td><td>Case Insensitive</td></tr>
<tr valign="top" class="odd"><td><a href="qimageioplugin.html">QImageIOPlugin</a></td><td><tt>imageformats</tt></td><td>Case Sensitive</td></tr>
<tr valign="top" class="even"><td><a href="qinputcontextplugin.html">QInputContextPlugin</a></td><td><tt>inputmethods</tt></td><td>Case Sensitive</td></tr>
<tr valign="top" class="odd"><td><a href="qkbddriverplugin.html">QKbdDriverPlugin</a></td><td><tt>kbddrivers</tt></td><td>Case Sensitive</td></tr>
<tr valign="top" class="even"><td><a href="qmousedriverplugin.html">QMouseDriverPlugin</a></td><td><tt>mousedrivers</tt></td><td>Case Sensitive</td></tr>
<tr valign="top" class="odd"><td><a href="qpictureformatplugin.html">QPictureFormatPlugin</a></td><td><tt>pictureformats</tt></td><td>Case Sensitive</td></tr>
<tr valign="top" class="even"><td><a href="qscreendriverplugin.html">QScreenDriverPlugin</a></td><td><tt>gfxdrivers</tt></td><td>Case Sensitive</td></tr>
<tr valign="top" class="odd"><td><a href="qscriptextensionplugin.html">QScriptExtensionPlugin</a></td><td><tt>script</tt></td><td>Case Sensitive</td></tr>
<tr valign="top" class="even"><td><a href="qsqldriverplugin.html">QSqlDriverPlugin</a></td><td><tt>sqldrivers</tt></td><td>Case Sensitive</td></tr>
<tr valign="top" class="odd"><td><a href="qstyleplugin.html">QStylePlugin</a></td><td><tt>styles</tt></td><td>Case Insensitive</td></tr>
<tr valign="top" class="even"><td><a href="qtextcodecplugin.html">QTextCodecPlugin</a></td><td><tt>codecs</tt></td><td>Case Sensitive</td></tr>
</table></p>
<p>But where is the <tt>plugins</tt> directory? When the application is run, Qt will first treat the application's executable directory as the <tt>pluginsbase</tt>. For example if the application is in <tt>C:\Program Files\MyApp</tt> and has a style plugin, Qt will look in <tt>C:\Program Files\MyApp\styles</tt>. (See <a href="qcoreapplication.html#applicationDirPath">QCoreApplication::applicationDirPath</a>() for how to find out where the application's executable is.) Qt will also look in the directory specified by QLibraryInfo::location(<a href="qlibraryinfo.html#LibraryLocation-enum">QLibraryInfo::PluginsPath</a>), which typically is located in <tt>QTDIR/plugins</tt> (where <tt>QTDIR</tt> is the directory where Qt is installed). If you want Qt to look in additional places you can add as many paths as you need with calls to <a href="qcoreapplication.html#addLibraryPath">QCoreApplication::addLibraryPath</a>(). And if you want to set your own path or paths you can use <a href="qcoreapplication.html#setLibraryPaths">QCoreApplication::setLibraryPaths</a>(). You can also use a <tt>qt.conf</tt> file to override the hard-coded paths that are compiled into the Qt library. For more information, see the <a href="qt-conf.html">Using qt.conf</a> documentation. Yet another possibility is to set the <tt>QT_PLUGIN_PATH</tt> environment variable before running the application. If set, Qt will look for plugins in the paths (separated by the system path separator) specified in the variable.</p>
<p>Suppose that you have a new style class called <tt>MyStyle</tt> that you want to make available as a plugin. The required code is straightforward, here is the class definition (<tt>mystyleplugin.h</tt>):</p>
<pre> class MyStylePlugin : public QStylePlugin
 {
 public:
     QStringList keys() const;
     QStyle *create(const QString &amp;key);
 };</pre>
<p>Ensure that the class implementation is located in a <tt>.cpp</tt> file (including the class definition):</p>
<pre> #include &quot;mystyleplugin.h&quot;

 QStringList MyStylePlugin::keys() const
 {
     return QStringList() &lt;&lt; &quot;MyStyle&quot;;
 }

 QStyle *MyStylePlugin::create(const QString &amp;key)
 {
     if (key.toLower() == &quot;mystyle&quot;)
         return new MyStyle;
     return 0;
 }

 Q_EXPORT_PLUGIN2(pnp_mystyleplugin, MyStylePlugin)</pre>
<p>(Note that <a href="qstyleplugin.html">QStylePlugin</a> is case insensitive, and the lower-case version of the key is used in our <a href="qstyleplugin.html#create">create()</a> implementation; most other plugins are case sensitive.)</p>
<p>For database drivers, image formats, text codecs, and most other plugin types, no explicit object creation is required. Qt will find and create them as required. Styles are an exception, since you might want to set a style explicitly in code. To apply a style, use code like this:</p>
<pre> QApplication::setStyle(QStyleFactory::create(&quot;MyStyle&quot;));</pre>
<p>Some plugin classes require additional functions to be implemented. See the class documentation for details of the virtual functions that must be reimplemented for each type of plugin.</p>
<p>Qt applications automatically know which plugins are available, because plugins are stored in the standard plugin subdirectories. Because of this applications don't require any code to find and load plugins, since Qt handles them automatically.</p>
<p>The default directory for plugins is <tt>QTDIR/plugins</tt> (where <tt>QTDIR</tt> is the directory where Qt is installed), with each type of plugin in a subdirectory for that type, e.g&#x2e; <tt>styles</tt>. If you want your applications to use plugins and you don't want to use the standard plugins path, have your installation process determine the path you want to use for the plugins, and save the path, e.g&#x2e; using <a href="qsettings.html">QSettings</a>, for the application to read when it runs. The application can then call <a href="qcoreapplication.html#addLibraryPath">QCoreApplication::addLibraryPath</a>() with this path and your plugins will be available to the application. Note that the final part of the path (e.g&#x2e;, <tt>styles</tt>) cannot be changed.</p>
<p>The normal way to include a plugin with an application is either to <a href="#static-plugins">compile it in with the application</a> or to compile it into a dynamic library and use it like any other library. If you want the plugin to be loadable then one approach is to create a subdirectory under the application and place the plugin in that directory. For more information about deployment, see the <a href="deployment.html">Deploying Qt Applications</a> documentation.</p>
<p>The <a href="tools-styleplugin.html">Style Plugin Example</a> shows how to implement a plugin that extends the <a href="qstyleplugin.html">QStylePlugin</a> base class.</p>
<a name="the-lower-level-api-extending-qt-applications"></a>
<h2>The Lower-Level API: Extending Qt Applications</h2>
<p>Not only Qt itself but also Qt application can be extended through plugins. This requires the application to detect and load plugins using <a href="qpluginloader.html">QPluginLoader</a>. In that context, plugins may provide arbitrary functionality and are not limited to database drivers, image formats, text codecs, styles, and the other types of plugin that extend Qt's functionality.</p>
<p>Making an application extensible through plugins involves the following steps:</p>
<ol type="1">
<li>Define a set of interfaces (classes with only pure virtual functions) used to talk to the plugins.</li>
<li>Use the <a href="qtplugin.html#Q_DECLARE_INTERFACE">Q_DECLARE_INTERFACE</a>() macro to tell Qt's <a href="metaobjects.html">meta-object system</a> about the interface.</li>
<li>Use <a href="qpluginloader.html">QPluginLoader</a> in the application to load the plugins.</li>
<li>Use <a href="qobject.html#qobject_cast">qobject_cast</a>() to test whether a plugin implements a given interface.</li>
</ol>
<p>Writing a plugin involves these steps:</p>
<ol type="1">
<li>Declare a plugin class that inherits from <a href="qobject.html">QObject</a> and from the interfaces that the plugin wants to provide.</li>
<li>Use the <a href="qobject.html#Q_INTERFACES">Q_INTERFACES</a>() macro to tell Qt's <a href="metaobjects.html">meta-object system</a> about the interfaces.</li>
<li>Export the plugin using the <a href="qtplugin.html#Q_EXPORT_PLUGIN2">Q_EXPORT_PLUGIN2</a>() macro.</li>
<li>Build the plugin using an suitable <tt>.pro</tt> file.</li>
</ol>
<p>For example, here's the definition of an interface class:</p>
<pre> class FilterInterface
 {
 public:
     virtual ~FilterInterface() {}

     virtual QStringList filters() const = 0;
     virtual QImage filterImage(const QString &amp;filter, const QImage &amp;image,
                                QWidget *parent) = 0;
 };

 Q_DECLARE_INTERFACE(FilterInterface,
                     &quot;com.trolltech.PlugAndPaint.FilterInterface/1.0&quot;)</pre>
<p>Here's the definition of a plugin class that implements that interface:</p>
<pre> #include &lt;QObject&gt;
 #include &lt;QStringList&gt;
 #include &lt;QImage&gt;

 #include &lt;plugandpaint/interfaces.h&gt;

 class ExtraFiltersPlugin : public QObject, public FilterInterface
 {
     Q_OBJECT
     Q_INTERFACES(FilterInterface)

 public:
     QStringList filters() const;
     QImage filterImage(const QString &amp;filter, const QImage &amp;image,
                        QWidget *parent);
 };</pre>
<p>The <a href="tools-plugandpaint.html">Plug &amp; Paint</a> example documentation explains this process in detail. See also <a href="designer-creating-custom-widgets.html">Creating Custom Widgets for Qt Designer</a> for information about issues that are specific to <i>Qt Designer</i>. You can also take a look at the <a href="tools-echoplugin.html">Echo Plugin Example</a> is a more trivial example on how to implement a plugin that extends Qt applications.</p>
<a name="loading-and-verifying-plugins-dynamically"></a>
<h2>Loading and Verifying Plugins Dynamically</h2>
<p>When loading plugins, the Qt library does some sanity checking to determine whether or not the plugin can be loaded and used. This provides the ability to have multiple versions and configurations of the Qt library installed side by side.</p>
<ul>
<li>Plugins linked with a Qt library that has a higher version number will not be loaded by a library with a lower version number.<br /><p><b>Example:</b> Qt 4.3&#x2e;0 will <i>not</i> load a plugin built with Qt 4.3&#x2e;1&#x2e;</p>
</li>
<li>Plugins linked with a Qt library that has a lower major version number will not be loaded by a library with a higher major version number.<br /><p><b>Example:</b> Qt 4.3&#x2e;1 will <i>not</i> load a plugin built with Qt 3.3&#x2e;1&#x2e; <br /> <b>Example:</b> Qt 4.3&#x2e;1 will load plugins built with Qt 4.3&#x2e;0 and Qt 4.2&#x2e;3&#x2e;</p>
</li>
<li>The Qt library and all plugins are built using a <i>build key</i>. The build key in the Qt library is examined against the build key in the plugin, and if they match, the plugin is loaded. If the build keys do not match, then the Qt library refuses to load the plugin.<br /><p><b>Rationale:</b> See the <a href="#the-build-key">The Build Key</a> section below.</p>
</li>
</ul>
<p>When building plugins to extend an application, it is important to ensure that the plugin is configured in the same way as the application. This means that if the application was built in release mode, plugins should be built in release mode, too.</p>
<p>If you configure Qt to be built in both debug and release modes, but only build applications in release mode, you need to ensure that your plugins are also built in release mode. By default, if a debug build of Qt is available, plugins will <i>only</i> be built in debug mode. To force the plugins to be built in release mode, add the following line to the plugin's project file:</p>
<pre> CONFIG += release</pre>
<p>This will ensure that the plugin is compatible with the version of the library used in the application.</p>
<a name="the-build-key"></a>
<h3>The Build Key</h3>
<p>When loading plugins, Qt checks the build key of each plugin against its own configuration to ensure that only compatible plugins are loaded; any plugins that are configured differently are not loaded.</p>
<p>The build key contains the following information:</p>
<ul>
<li>Architecture, operating system and compiler.<p><i>Rationale:</i> In cases where different versions of the same compiler do not produce binary compatible code, the version of the compiler is also present in the build key.</p>
</li>
<li>Configuration of the Qt library. The configuration is a list of the missing features that affect the available API in the library.<p><i>Rationale:</i> Two different configurations of the same version of the Qt library are not binary compatible. The Qt library that loads the plugin uses the list of (missing) features to determine if the plugin is binary compatible.</p>
<p><i>Note:</i> There are cases where a plugin can use features that are available in two different configurations. However, the developer writing plugins would need to know which features are in use, both in their plugin and internally by the utility classes in Qt. The Qt library would require complex feature and dependency queries and verification when loading plugins. Requiring this would place an unnecessary burden on the developer, and increase the overhead of loading a plugin. To reduce both development time and application runtime costs, a simple string comparision of the build keys is used.</p>
</li>
<li>Optionally, an extra string may be specified on the configure script command line.<p><i>Rationale:</i> When distributing binaries of the Qt library with an application, this provides a way for developers to write plugins that can only be loaded by the library with which the plugins were linked.</p>
</li>
</ul>
<p>For debugging purposes, it is possible to override the run-time build key checks by setting the <tt>QT_NO_PLUGIN_CHECK</tt> environment variable to a non-zero value in the environment from which your application is launched.</p>
<a name="static-plugins"></a>
<h2>Static Plugins</h2>
<p>Plugins can be linked statically against your application. If you build the static version of Qt, this is the only option for including Qt's predefined plugins.</p>
<p>When compiled as a static library, Qt provides the following static plugins:</p>
<p><table align="center" cellpadding="2" cellspacing="1" border="0">
<thead><tr valign="top" class="qt-style"><th>Plugin name</th><th>Type</th><th>Description</th></tr></thead>
<tr valign="top" class="odd"><td><tt>qtaccessiblecompatwidgets</tt></td><td>Accessibility</td><td>Accessibility for Qt 3 support widgets</td></tr>
<tr valign="top" class="even"><td><tt>qtaccessiblewidgets</tt></td><td>Accessibility</td><td>Accessibility for Qt widgets</td></tr>
<tr valign="top" class="odd"><td><tt>qdecorationdefault</tt></td><td>Decorations (Qtopia)</td><td>Default style</td></tr>
<tr valign="top" class="even"><td><tt>qdecorationwindows</tt></td><td>Decorations (Qtopia)</td><td>Windows style</td></tr>
<tr valign="top" class="odd"><td><tt>qgif</tt></td><td>Image formats</td><td>GIF</td></tr>
<tr valign="top" class="even"><td><tt>qjpeg</tt></td><td>Image formats</td><td>JPEG</td></tr>
<tr valign="top" class="odd"><td><tt>qmng</tt></td><td>Image formats</td><td>MNG</td></tr>
<tr valign="top" class="even"><td><tt>qimsw_multi</tt></td><td>Input methods (Qtopia)</td><td>Input Method Switcher</td></tr>
<tr valign="top" class="odd"><td><tt>qwstslibmousehandler</tt></td><td>Mouse drivers (Qtopia)</td><td><tt>tslib</tt> mouse</td></tr>
<tr valign="top" class="even"><td><tt>qgfxtransformed</tt></td><td>Graphic drivers (Qtopia)</td><td>Transformed screen</td></tr>
<tr valign="top" class="odd"><td><tt>qgfxvnc</tt></td><td>Graphic drivers (Qtopia)</td><td>VNC</td></tr>
<tr valign="top" class="even"><td><tt>qscreenvfb</tt></td><td>Graphic drivers (Qtopia)</td><td>Virtual frame buffer</td></tr>
<tr valign="top" class="odd"><td><tt>qsqldb2</tt></td><td>SQL driver</td><td>IBM DB2</td></tr>
<tr valign="top" class="even"><td><tt>qsqlibase</tt></td><td>SQL driver</td><td>Borland InterBase</td></tr>
<tr valign="top" class="odd"><td><tt>qsqlite</tt></td><td>SQL driver</td><td><a href="3rdparty.html#sqlite">SQLite</a> version 3</td></tr>
<tr valign="top" class="even"><td><tt>qsqlite2</tt></td><td>SQL driver</td><td><a href="3rdparty.html#sqlite">SQLite</a> version 2</td></tr>
<tr valign="top" class="odd"><td><tt>qsqlmysql</tt></td><td>SQL driver</td><td>MySQL</td></tr>
<tr valign="top" class="even"><td><tt>qsqloci</tt></td><td>SQL driver</td><td>Oracle (OCI)</td></tr>
<tr valign="top" class="odd"><td><tt>qsqlodbc</tt></td><td>SQL driver</td><td>Open Database Connectivity (ODBC)</td></tr>
<tr valign="top" class="even"><td><tt>qsqlpsql</tt></td><td>SQL driver</td><td>PostgreSQL</td></tr>
<tr valign="top" class="odd"><td><tt>qsqltds</tt></td><td>SQL driver</td><td>Sybase Adaptive Server (TDS)</td></tr>
<tr valign="top" class="even"><td><tt>qcncodecs</tt></td><td>Text codecs</td><td>Simplified Chinese (People's Republic of China)</td></tr>
<tr valign="top" class="odd"><td><tt>qjpcodecs</tt></td><td>Text codecs</td><td>Japanese</td></tr>
<tr valign="top" class="even"><td><tt>qkrcodecs</tt></td><td>Text codecs</td><td>Korean</td></tr>
<tr valign="top" class="odd"><td><tt>qtwcodecs</tt></td><td>Text codecs</td><td>Traditional Chinese (Taiwan)</td></tr>
</table></p>
<p>To link statically against those plugins, you need to use the <a href="qtplugin.html#Q_IMPORT_PLUGIN">Q_IMPORT_PLUGIN</a>() macro in your application and you need to add the required plugins to your build using <tt>QTPLUGIN</tt>. For example, in your <tt>main.cpp</tt>:</p>
<pre> #include &lt;QApplication&gt;
 #include &lt;QtPlugin&gt;

 Q_IMPORT_PLUGIN(qjpeg)
 Q_IMPORT_PLUGIN(qgif)
 Q_IMPORT_PLUGIN(qkrcodecs)

 int main(int argc, char *argv[])
 {
     QApplication app(argc, argv);
     ...
     return app.exec();
 }</pre>
<p>In the <tt>.pro</tt> file for your application, you need the following entry:</p>
<pre> QTPLUGIN     += qjpeg \
                 qgif \
                 qkrcodecs</pre>
<p>It is also possible to create your own static plugins, by following these steps:</p>
<ol type="1">
<li>Add <tt>CONFIG += static</tt> to your plugin's <tt>.pro</tt> file.</li>
<li>Use the <a href="qtplugin.html#Q_IMPORT_PLUGIN">Q_IMPORT_PLUGIN</a>() macro in your application.</li>
<li>Link your application with your plugin library using <tt>LIBS</tt> in the <tt>.pro</tt> file.</li>
</ol>
<p>See the <a href="tools-plugandpaint.html">Plug &amp; Paint</a> example and the associated <a href="tools-plugandpaintplugins-basictools.html">Basic Tools</a> plugin for details on how to do this.</p>
<a name="the-plugin-cache"></a>
<h2>The Plugin Cache</h2>
<p>In order to speed up loading and validation of plugins, some of the information that is collected when plugins are loaded is cached through <a href="qsettings.html">QSettings</a>. This includes information about whether or not a plugin was successfully loaded, so that subsequent load operations don't try to load an invalid plugin. However, if the &quot;last modified&quot; timestamp of a plugin has changed, the plugin's cache entry is invalidated and the plugin is reloaded regardless of the values in the cache entry, and the cache entry itself is updated with the new result.</p>
<p>This also means that the timestamp must be updated each time the plugin or any dependent resources (such as a shared library) is updated, since the dependent resources might influence the result of loading a plugin.</p>
<p>Sometimes, when developing plugins, it is necessary to remove entries from the plugin cache. Since Qt uses <a href="qsettings.html">QSettings</a> to manage the plugin cache, the locations of plugins are platform-dependent; see <a href="qsettings.html#platform-specific-notes">the QSettings documentation</a> for more information about each platform.</p>
<p>For example, on Windows the entries are stored in the registry, and the paths for each plugin will typically begin with either of these two strings:</p>
<pre> HKEY_CURRENT_USER\Software\Trolltech\OrganizationDefaults\Qt Plugin Cache 4.2.debug
 HKEY_CURRENT_USER\Software\Trolltech\OrganizationDefaults\Qt Plugin Cache 4.2.false</pre>
<a name="debugging-plugins"></a>
<h2>Debugging Plugins</h2>
<p>There are a number of issues that may prevent correctly-written plugins from working with the applications that are designed to use them. Many of these are related to differences in the way that plugins and applications have been built, often arising from separate build systems and processes.</p>
<p>The following table contains descriptions of the common causes of problems developers experience when creating plugins:</p>
<p><table align="center" cellpadding="2" cellspacing="1" border="0">
<thead><tr valign="top" class="qt-style"><th>Problem</th><th>Cause</th><th>Solution</th></tr></thead>
<tr valign="top" class="odd"><td>Plugins sliently fail to load even when opened directly by the application. <i>Qt Designer</i> shows the plugin libraries in its <b>Help|About Plugins</b> dialog, but no plugins are listed under each of them.</td><td>The application and its plugins are built in different modes.</td><td>Either share the same build information or build the plugins in both debug and release modes by appending the <tt>debug_and_release</tt> to the <a href="qmake-variable-reference.html#config">CONFIG</a> variable in each of their project files.</td></tr>
<tr valign="top" class="even"><td>A valid plugin that replaces an invalid (or broken) plugin fails to load.</td><td>The entry for the plugin in the plugin cache indicates that the original plugin could not be loaded, causing Qt to ignore the replacement.</td><td>Either ensure that the plugin's timestamp is updated, or delete the entry in the <a href="#the-plugin-cache">plugin cache</a>.</td></tr>
</table></p>
<p>You can also use the <tt>QT_DEBUG_PLUGINS</tt> environment variable to obtain diagnostic information from Qt about each plugin it tries to load. Set this variable to a non-zero value in the environment from which your application is launched.</p>
<p>See also <a href="qpluginloader.html">QPluginLoader</a>, <a href="qlibrary.html">QLibrary</a>, and <a href="tools-plugandpaint.html">Plug &amp; Paint Example</a>.</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="30%">Copyright &copy; 2008 <a href="trolltech.html">Trolltech</a></td>
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="30%" align="right"><div align="right">Qt 4.3.5</div></td>
</tr></table></div></address></body>
</html>
